﻿

using Autofac;
using AutoMapper;
using MiningCore.Blockchain.ZCash.Configuration;
using MiningCore.Configuration;
using MiningCore.Extensions;
using MiningCore.Messaging;
using MiningCore.Notifications;
using MiningCore.Persistence;
using MiningCore.Persistence.Repositories;
using MiningCore.Time;
using MiningCore.Util;
using Newtonsoft.Json;

namespace MiningCore.Blockchain.ZCash
{
    [CoinMetadata(CoinType.ZEC)]
    public class ZCashPool : ZCashPoolBase<ZCashJob>
    {
        public ZCashPool(IComponentContext ctx,
            JsonSerializerSettings serializerSettings,
            IConnectionFactory cf,
            IStatsRepository statsRepo,
            IMapper mapper,
            IMasterClock clock,
            IMessageBus messageBus,
            NotificationService notificationService) :
            base(ctx, serializerSettings, cf, statsRepo, mapper, clock, messageBus, notificationService)
        {
        }

        private ZCashPoolConfigExtra extraConfig;

        public override void Configure(PoolConfig poolConfig, ClusterConfig clusterConfig)
        {
            base.Configure(poolConfig, clusterConfig);

            extraConfig = poolConfig.Extra.SafeExtensionDataAs<ZCashPoolConfigExtra>();

            if (string.IsNullOrEmpty(extraConfig?.ZAddress))
                logger.ThrowLogPoolStartupException($"Pool z-address is not configured", LogCat);
        }
    }
}
